package com.ruoyi.web.controller.business;

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.bean.BeanUtils;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.system.domain.FyProjectApply;
import com.ruoyi.system.domain.FyProjectApplyAncillary;
import com.ruoyi.system.domain.vo.business.*;
import com.ruoyi.system.service.IFyProjectApplyAncillaryService;
import com.ruoyi.system.service.IFyProjectApplyService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.List;


/**
 * 扶垚计划项目申报Controller
 *
 * @author ruoyi
 * @date 2024-02-28
 */
@Controller
@Api(tags = {"扶垚计划项目申报"})
@RequestMapping("/system/fyProjectApply")
public class FyProjectApplyController extends BaseController {

    @Autowired
    private IFyProjectApplyService fyProjectApplyService;

    @Autowired
    private IFyProjectApplyAncillaryService ancillaryService;

    /**
     * 查询扶垚计划项目申报列表
     */
    @ApiOperation("查询扶垚计划项目申报列表")
    @PreAuthorize("@ss.hasPermi('system:fyProjectApply:list')")
    @PostMapping("/list")
    @ResponseBody
    public AjaxResult<Page<FyProjectApplySelectListVO>> list(@RequestBody FyProjectApplySelectListDto dto) {
        if (dto.getStatus() != -1) {
            dto.setApprovalUserId(getUserId());
        }
        Page<FyProjectApplySelectListVO> list = fyProjectApplyService.pageList(dto);
        return success(list);
    }


    /**
     * 查询扶垚计划项目信息管理列表
     */
    @ApiOperation("查询扶垚计划项目信息管理列表")
    @PreAuthorize("@ss.hasPermi('system:fyProjectApply:manageList')")
    @PostMapping("/manageList")
    @ResponseBody
    public AjaxResult<Page<FyProjectApplySelectManageListVO>> manageList(@RequestBody FyProjectApplySelectManageListDto dto) {
        dto.setStatus("1");
        Page<FyProjectApplySelectManageListVO> list = fyProjectApplyService.pageManageList(dto);
        return success(list);
    }

    /**
     * 导出扶垚计划项目申报列表
     */
    @ApiOperation("导出扶垚计划项目申报列表")
    //@RequiresPermissions("system:application:export")
    @Log(title = "扶垚计划项目申报", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(FyProjectApplySelectListDto dto) {
        List<FyProjectApplySelectListVO> list = fyProjectApplyService.list(dto);
        ExcelUtil<FyProjectApplySelectListVO> util = new ExcelUtil<>(FyProjectApplySelectListVO.class);
        return util.exportExcel(list, "扶垚计划项目申报数据");
    }

    /**
     * 扶垚计划项目申报详情
     */
    @ApiOperation("扶垚计划项目申报详情")
    @PreAuthorize("@ss.hasPermi('system:fyProjectApply:detail')")
    @GetMapping("/edit/{id}")
    @ResponseBody
    public AjaxResult edit(@PathVariable("id") Long id) {
        FyProjectApplyDetailVO vo = fyProjectApplyService.selectFyProjectApplyDetailVOById(id);
        return success(vo);
    }

    /**
     * 删除扶垚计划项目申报
     */
    @ApiOperation("删除扶垚计划项目申报")
    //@RequiresPermissions("system:application:remove")
    @Log(title = "扶垚计划项目申报", businessType = BusinessType.DELETE)
    @PostMapping("/remove")
    @ResponseBody
    public AjaxResult remove(Long id) {
        ancillaryService.remove(Wrappers.lambdaQuery(FyProjectApplyAncillary.class).
                eq(FyProjectApplyAncillary::getFyProjectApplyId,id));
        return toAjax(fyProjectApplyService.removeById(id));
    }
}
